<?php

Yii::import('application.models._base.BaseCustomer');


class CustomerEdit extends BaseCustomer
{
	public $keywords;
	public $is_agree;
	public $oldpass;
	public $newpass;
	public $conpass;
	public static function model($className=__CLASS__) {
		return parent::model($className);
	}
	
	
	public function rules() {
		return array(
			array('user_name, password, email, created, status', 'required'),
			array('user_name','length','min'=>5),
			array('user_name','match','pattern'=>'/[0-9A-Za-z]+/','message'=>
				'Usernames must be at least 5 characters, and alphanumeric only (A-Z / 0-9). No spaces or special characters are allowed.'
			),
			array('user_name','unique','className'=>'Customer'),
			array('email', 'unique','className'=>'Customer'),
			array('user_name, password', 'length', 'max'=>45),			
			array('email', 'email'),
			array('id,keywords,user_name, password, email, created, status', 'safe', 'on'=>'search'),
			array('is_agree','in','range'=>array(1),'message'=>'please agree the privacy policy!'),
		);
	}
	
	public function beforeSave(){
		$this->password=md5($this->password);
		return true;
	}
	
	public function attributeLabels() {
		return array(
				'id' => Yii::t('app', 'ID'),
				'user_name' => Yii::t('app', 'User Name'),
				'password' => Yii::t('app', 'Create Password'),
				'conpassword' => Yii::t('app', 'Verify Password'),
				'email' => Yii::t('app', 'Email'),
				'created' => Yii::t('app', 'Created'),
				'status' => Yii::t('app', 'Status'),
		);
	}
	
	public function search() {
		$criteria = new CDbCriteria;
		if(!empty($this->keywords)){
			$criteria->compare('user_name', $this->keywords, true,'OR');
			$criteria->compare('email', $this->keywords, true,'OR');
		}
		return new CActiveDataProvider($this, array(
				'criteria' => $criteria,
		));
	}
		
}